package cn.wobuhekele;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.wobuhekele.mapper.HumanMapper;

import java.util.List;
import java.util.Map;

/**
 * 
 */

/**
 * <b>功能说明:</b>
 * <p>
 * 
 * </p>
 * </br> <b>设计思想、目的:</b>
 * <p>
 * 
 * </p>
 * </br><b>设计缺陷: </b>
 * <p>
 * </p>
 * 
 * @author xchen
 * @CreateDate 2017-1-6 - 下午2:55:33
 * @Encoding UTF-8
 * @Version 1.0  
 */ 

@Controller
//@ResponseBody
@EnableAutoConfiguration
@ComponentScan 
public class Application
{
	private org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Application.class);
	
	@Autowired
	private HumanRespisitory humanRespisitory;
	
	@Autowired
	private HumanMapper humanMapper;
	
	@RequestMapping("/")
	String home()
	{
		return "index";  
	}
	
	@RequestMapping("/add")
	Human addHuman()
	{
		Human human = new Human();
		human.setAge("21");
		human.setSex("女");
		
		return humanRespisitory.save(human);
	}

	@RequestMapping("/findHuman")
	List<Human> findHuman()
	{
		List<Human> findAll = humanRespisitory.findAll();
		
		return humanRespisitory.findAll();
	}
	
	@RequestMapping("/findHumanjsp")
	String findHuman(Map<String,Object> map,HttpServletRequest request)
	{
		List<Human> findAll = humanRespisitory.findAll();
		map.put("findAll", findAll);
		request.setAttribute("tttt", "request中的数据");
		return "index";
	}
	
	@RequestMapping("/findById/{id}")
	Human findById(@PathVariable("id")Integer id,Map<String,Object> map)
	{
		
//		return humanRespisitory.findById(id);
		logger.info("查询的用户"+humanMapper.selectById(id));
		
		return humanMapper.selectById(id);
	}
	
	public static void main(String[] args) throws Exception
	{
		SpringApplication.run(Application.class, args);
	}
}
